/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.charge.web;


import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.service.IBusinessCodeService;
import com.ce.pms.charge.vo.BusinessCodeVO;
import com.ce.pms.exception.BusinessException;
import com.sitechasia.webx.components.xtable.util.ExtremeUtils;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：<br>
 * @author 罗军林 创建日期：2008-8-4
 */
public class BusinessCodeAction extends PmsBaseAction{
	IBusinessCodeService businessCodeService;

	/**
	 * 功能描述:初始化主页面<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-5<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void initMain(){}

	/**
	 * 功能描述:初始化增加页面<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-5<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void initAdd(){
		setAttribute("isEdit", false);
	}


	/**
	 * 功能描述:初始化修改页面<br>
	 * @param keyword<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-5<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void initEdit(@Read(key = "keyword") Long keyword){
		BusinessCodeVO businessCodeVO=businessCodeService.findBusinessCodeByKeyword(keyword);
		setAttribute("businessCode", businessCodeVO);
		setAttribute("isEdit", true);
	}

	/**
	 * 功能描述:选择交易码ACTION<br>
	 * <br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-6<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void initSelectBusinessCode(@Read(key="iframeName")String iframeName,
										@Read(key="code")String code){
		setAttribute("iframeName",iframeName);
		setAttribute("businessCodeList", businessCodeService.getAllNotUseBusinessCodeList(code));
	}

	/**
	 * 功能描述:<br>
	 * @param businessCodeVO<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void add(@Read BusinessCodeVO businessCodeVO){
		businessCodeVO.setCreator(this.getUserId());
		businessCodeService.addBusinessCode(businessCodeVO);
	}

	/**
	 * 功能描述:<br>
	 * @param businessCodeVO<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void edit(@Read BusinessCodeVO businessCodeVO){
		businessCodeVO.setCreator(this.getUserId());
		businessCodeService.editBusinessCode(businessCodeVO);
	}

	/**
	 * 功能描述:<br>
	 * @param keyword<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void delete(@Read(key = "keyword") Long keyword){
		try{
			businessCodeService.deleteBusinessCodeByKeyword(keyword);
		}catch (Throwable e) {
			throw new BusinessException("charge:businessCodeDelete_fail",BusinessException.WARNING);
		}
	}

	/**
	 * 功能描述:<br>
	 * @param pageSize
	 * @param pageNo<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-4<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void list(@Read(key = "ec_crd",defaultValue="15") int pageSize,
					@Read(key = "ec_p",defaultValue="1")	int pageNo){
		BusinessCodeVO condition = new BusinessCodeVO();
		condition.setOrderStr( ExtremeUtils.getOrderString(this.getRequest()) );
		Page page=businessCodeService.queryBusinessCode(condition, pageNo, pageSize);

		setAttribute("totalRows", new Integer((int) page.getTotalCount()));
		setAttribute("businessCodeList", page.getResult());
	}


	/**
	 * 功能描述:检查交易码的唯一性<br>
	 * @param newBizCode
	 * @param oldBizCode<br>
	 * Create author:罗军林<br>
	 * Create on:2008-8-5<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void checkBizCode(@Read BusinessCodeVO condition){
		Long result = businessCodeService.countBusinessCodeBizCode(condition);
		if(result <= 0){
			renderText("true");
		}else{
			renderText("已经存在");
		}
	}

	/**
	 * @return businessCodeServicegetBusinessCodeService
	 */
	public IBusinessCodeService getBusinessCodeService() {
		return businessCodeService;
	}
	/**
	 * @param businessCodeService the businessCodeService to set
	 */
	public void setBusinessCodeService(IBusinessCodeService businessCodeService) {
		this.businessCodeService = businessCodeService;
	}



}
